package com.LeeCode;

/**
 * 找出字符串中第一个匹配项的下标
 */

public class Code028 {
    public static void main(String[] args) {
        String haystack = "a";
        String needle = "a";
        System.out.println(new Code028().strStr(haystack, needle));

    }

    public int strStr(String haystack, String needle) {

        int ans = -1;
        for (int i = 0; i < haystack.length(); i++) {
            if(haystack.startsWith(needle, i)){
                ans = i;
                break;
            }
        }
        return ans;
    }
}
